<?php
namespace app\controller;

use app\BaseController;
use app\Request;
use think\exception\ValidateException;

class Index extends BaseController
{
    public function index()
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">14载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
    }

    public function hello($name = 'ThinkPHP6')
    {
        return 'hello,' . $name;
    }
//    添加页面
function addShow(){
        return view('index/addShow');
}
//添加
function addData(Request $request){
        $postData=$request->all();
    try {
        validate(\app\validate\User::class)->check($postData);
    } catch (ValidateException $e) {
        // 验证失败 输出错误信息
        dd($e->getError());
    }
    $file=$request->file('file');
    $savename = \think\facade\Filesystem::disk('public')->putFile( 'topic', $file);
    $image = \think\Image::open("$file");
// 按照原图的比例生成一个最大为200*200的缩略图并保存为thumb.png
    $image->thumb(150, 150)->save("storage/$savename");
// 给原图左上角添加水印并保存water_image.png
    $image->water('./logo.png')->save("storage/$savename");
    $postData['file']=$savename;
    $checkData=\app\model\Index::addData($postData);
    if($checkData){
        return '添加成功';
    }
}
//展示
function showData(){
    $data=\app\model\Index::showData();
    return view('index/showData',compact('data'));
}
}
